<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
		<script src="js/mui.min.js"></script>
		<script type="text/javascript" src="js/publicurl.js" ></script>
		<script type="text/javascript" src="js/my.js" ></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/style.css" />
		<link rel="stylesheet" href="css/ymk.css" />
		<script>
			var userId = localStorage.getItem("userInfo");
			
			if(userId>0) {
				my.jump("index.html","index");
			}
		</script>
	</head>
	
	<body>
		<!--<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">登录123</h1>
		</header>-->
		<div class="mui-content ">
			<div class="logo-img">
				<img src="images/logo.png" / style="">

			</div>
			<!--输入mform按下回车键快速创建输入框-->
			<div class="public-margin-top">
				<form class="mui-inputgroup">
					<div class="denglu-a" style="margin-top: 20px;">
			    	<div class="denglu-a-l" >
			    		账号
			    	</div>
			    	<div class="denglu-a-r">
			    		<input type="text" placeholder="请输入您的手机号" id="phone">
			    	
			    	</div>
			    </div>
			    <div class="denglu-a">
			    	<div class="denglu-a-l">
			    		密码
			    	</div>
			    	<div class="denglu-a-r">
			    		<input type="password" placeholder="请输入您的密码">
			    	</div>
			    </div>
				</form>
				<div class="mui-content-padded">
					<button class="btn" id="login">登&nbsp;录</button>
				</div>
				<div style="width:90%;margin:0 auto;">
					<button class="mui-btn-link mui-pull-left" style="padding: 0px;" id="forgetpassword">忘记密码？</button>
					<button class="mui-btn-link mui-pull-right" style="padding: 0px;" id="register">去注册</button>
				</div>
			</div>
		</div>
		<script type="text/javascript" charset="UTF-8">
			mui.init();
			var url=puburl.url+"/dangxia";
			var login = document.getElementById("login");
			var register = document.getElementById("register");
			var forgetpassword = document.getElementById("forgetpassword");
			register.addEventListener('tap', function() {
				mui.openWindow({
					url: 'register.html',
					id: 'register'
				})
			});
			forgetpassword.addEventListener('tap', function() {
				mui.openWindow({
					url: 'forget_password.html',
					id: 'forgetpassword'
				});
			});
			login.addEventListener('tap', function() {
				var input = document.getElementsByTagName("input");
				var username = input[0].value;
				var password = input[1].value;
				var phone = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
				if(username == '') {
					mui.toast("手机号不能为空", {
						duration: 'short',
						type: 'div'
					});
					return;
				}
				if(password == '') {
					mui.toast("密码不能为空", {
						duration: 'short',
						type: 'div'
					});
					return;
				}
				if(username.length != 11) {
					mui.toast("手机号应为11位", {
						duration: 'short',
						type: 'div'
					});
					return;
				}
				if(!phone.test(username.trim())) {
					mui.toast("手机号格式不正确");
					return;
				}
				var realUrl=url+"/user/login";
				mui.ajax(realUrl, {
					data: {
						username: username,
						psw: password
					},
					dataType: 'json', //服务器返回json格式数据 
					type: 'post', //HTTP请求类型
					timeout: 10000, //超时时间设置为10秒；
					success: function(data) {
						if(data.code == 0) { 
							
							localStorage.clear();
							
							var d=JSON.stringify(data.data.id);
							
							localStorage.setItem("userInfo",d);
							localStorage.setItem("url",url);
							
							if(data.data.name==""||data.data.name==null){
								my.jump("perfectinfo.html","perfectinfo");

							}else{
								my.jump("index.html","main");
							}
							
						}else{
							mui.toast(data.msg);
						}

					},
					error: function(xhr, type, errorThrown) { //异常处理；
						console.log(type);
					}
				});
			})
		</script>

	</body>

</html>